package com.example.administrator.myapplication.base;

import android.app.Activity;
import android.app.Application;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle;

import com.example.administrator.myapplication.utils.LiteOrmUtil;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;

import butterknife.ButterKnife;

public class MyApplication extends Application {
    public static Application myApp;
    public NetWorkType netWorkType = NetWorkType.NULL;
    public static String appCachePath;
    public static String appFilePath;
    public static String appSDCachePath;
    public static String appSDFilePath;

    public enum NetWorkType {
        WIFI, ETHERNET, MOBILE, NetWorkType, NULL
    }


    @Override
    public void onCreate() {
        super.onCreate();
        LiteOrmUtil.init(this);
        ButterKnife.setDebug(true);
        myApp = this;


        IntentFilter filter = new IntentFilter();
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        //typeface = Typeface.createFromAsset(getAssets(), "fzlt.ttf");
        appCachePath = getCacheDir().getPath();
        appFilePath = getFilesDir().getPath();

        registerActivityLifecycleCallbacks(activityLifecycleCallbacks);

        ZXingLibrary.initDisplayOpinion(this);

    }


    public void onTerminate() {
        super.onTerminate();
    }


    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }

    ActivityLifecycleCallbacks activityLifecycleCallbacks = new ActivityLifecycleCallbacks() {
        @Override
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            ActivityManager.getInstance().pushActivity(activity);
        }

        @Override
        public void onActivityStarted(Activity activity) {

        }

        @Override
        public void onActivityResumed(Activity activity) {

        }

        @Override
        public void onActivityPaused(Activity activity) {

        }

        @Override
        public void onActivityStopped(Activity activity) {

        }

        @Override
        public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

        }

        @Override
        public void onActivityDestroyed(Activity activity) {
            ActivityManager.getInstance().exitActivity(activity);
        }
    };


}
